* This file cleans the GenScape data and creates a file of daily car loading by rail terminal

use "/PRR_Rail_Daily_Hughes.dta", clear
gen date = dofc(analysis_date)
format date %td
gen year = year(date)
gen month = month(date)
gen day = day(date)
sort display_name year month
*by display_name year month: egen cars_monthly = sum(num_cars)
gen keep = 0
replace keep = 1 if display_name == "Hess - Tioga"
replace keep = 1 if display_name == "Enbridge - Berthold"
replace keep = 1 if display_name == "EOG - Stanley"
replace keep = 1 if display_name == "Crestwood - Epping COLT"
replace keep = 1 if display_name == "Savage - Trenton"
replace keep = 1 if display_name == "Musket - Dore"
replace keep = 1 if display_name == "GLP - Beulah"
replace keep = 1 if display_name == "Lario - Dickinson"
replace keep = 1 if display_name == "BakkenLink - Fryburg"
replace keep = 1 if display_name == "GLP - Stampede"
replace keep = 1 if display_name == "DTS - New Town"
replace keep = 1 if display_name == "PAA - Van Hook"
replace keep = 1 if display_name == "Eighty-Eight Oil - Guernsey"
keep if keep == 1 
* RR's
gen rr = ""
replace rr = "BNSF" if display_name == "Hess - Tioga"
replace rr = "BNSF" if display_name == "Enbridge - Berthold"
replace rr = "BNSF"  if display_name == "EOG - Stanley"
replace rr = "BNSF"  if display_name == "Crestwood - Epping COLT"
replace rr = "BNSF"  if display_name == "Savage - Trenton"
replace rr = "BNSF"  if display_name == "Musket - Dore"
replace rr = "BNSF"  if display_name == "GLP - Beulah"
replace rr = "BNSF"  if display_name == "Lario - Dickinson"
replace rr = "BNSF"  if display_name == "BakkenLink - Fryburg"
replace rr = "CPUS" if display_name == "GLP - Stampede"
replace rr = "CPUS" if display_name == "DTS - New Town"
replace rr = "CPUS" if display_name == "PAA - Van Hook"
* Routes
gen route = ""
replace route = "north" if display_name == "Hess - Tioga"
replace route = "north" if display_name == "Enbridge - Berthold"
replace route = "north"  if display_name == "EOG - Stanley"
replace route = "north"  if display_name == "Crestwood - Epping COLT"
replace route = "north"  if display_name == "Savage - Trenton"
replace route = "north"  if display_name == "Musket - Dore"
replace route = "mid"  if display_name == "GLP - Beulah"
replace route = "south"  if display_name == "Lario - Dickinson"
replace route = "south"  if display_name == "BakkenLink - Fryburg"
replace route = "north" if display_name == "GLP - Stampede"
replace route = "south" if display_name == "DTS - New Town"
replace route = "south" if display_name == "PAA - Van Hook"
save "/disk/homedirs/nber/jehughes/data/PRR_Rail_Daily_Hughes_clean.dta", replace

* Make a monthly version of Genscape data
use "/disk/homedirs/nber/jehughes/data/PRR_Rail_Daily_Hughes_clean.dta", clear
sort year month
collapse (sum) num_cars, by(year month)
gen date = ym(year, month)
format date %tm
sort date
save "/disk/homedirs/nber/jehughes/data/PRR_Rail_Daily_Hughes_monthly.dta", replace

* Make a weekly version of Genscape data
use "/disk/homedirs/nber/jehughes/data/PRR_Rail_Daily_Hughes_clean.dta", clear
gen week = week(date)
sort year week
collapse (sum) num_cars, by(year week)
gen date = yw(year, week)
format date %tw
sort date
save "/disk/homedirs/nber/jehughes/data/PRR_Rail_Daily_Hughes_weekly.dta", replace

